package cn.iocoder.yudao.module.famous.doctor.controller.app.opinion;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.famous.doctor.controller.admin.opinion.vo.*;
import cn.iocoder.yudao.module.famous.doctor.convert.opinion.OpinionConvert;
import cn.iocoder.yudao.module.famous.doctor.dal.dataobject.opinion.OpinionDO;
import cn.iocoder.yudao.module.famous.doctor.service.opinion.OpinionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "用户 App - 意见反馈")
@RestController
@RequestMapping("/famous.doctor/opinion/app")
@Validated
public class AppOpinionController {

    @Resource
    private OpinionService opinionService;

    @PostMapping("/create")
    @Operation(summary = "创建意见反馈")
    public CommonResult<Long> createOpinion(@Valid @RequestBody OpinionCreateReqVO createReqVO) {
        return success(opinionService.createOpinion(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新意见反馈")
    public CommonResult<Boolean> updateOpinion(@Valid @RequestBody OpinionUpdateReqVO updateReqVO) {
        opinionService.updateOpinion(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除意见反馈")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteOpinion(@RequestParam("id") Long id) {
        opinionService.deleteOpinion(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得意见反馈")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<OpinionRespVO> getOpinion(@RequestParam("id") Long id) {
        OpinionDO opinion = opinionService.getOpinion(id);
        return success(OpinionConvert.INSTANCE.convert(opinion));
    }

    @GetMapping("/list")
    @Operation(summary = "获得意见反馈列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    public CommonResult<List<OpinionRespVO>> getOpinionList(@RequestParam("ids") Collection<Long> ids) {
        List<OpinionDO> list = opinionService.getOpinionList(ids);
        return success(OpinionConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得意见反馈分页")
    public CommonResult<PageResult<OpinionRespVO>> getOpinionPage(@Valid OpinionPageReqVO pageVO) {
        PageResult<OpinionDO> pageResult = opinionService.getOpinionPage(pageVO);
        return success(OpinionConvert.INSTANCE.convertPage(pageResult));
    }

}
